local skel = fk.CreateSkill {
  name = "lb__bishi",
}

Fk:loadTranslationTable {
  ["lb__bishi"] = "庇世",
  --[":lb__bishi"] = "当不处于横置状态的角色造成伤害时，你可以防止之。当一名角色对你使用牌时，其可以横置，然后重铸一张牌。",
  --10.2
  --[":lb__bishi"] = "当不处于横置状态的角色造成伤害时，你可以防止之。其他角色对你使用牌无距离限制，且其对你使用牌时可以横置，然后弃置一张牌。",
  --10.5
  [":lb__bishi"] = "每回合限一次，当不处于横置状态的角色造成伤害时，你可以防止之。其他角色对你使用牌无距离限制，且其对你使用牌时可以横置，然后弃置一张牌。",

  ["#lb__bishi"] = "庇世：你可以防止 %dest 即将造成的 %arg点%arg2伤害",
  ["#lb__bishi_chain"] = "庇世：你可以横置，然后弃置一张牌",
  ["#lb__bishi_recast"] = "庇世：请弃置一张牌",

  ["$lb__bishi1"] = "金石之志！",
  ["$lb__bishi2"] = "集众生之愿，护佑此方。",
  ["$lb__bishi3"] = "我来抵挡攻势。",
  ["$lb__bishi4"] = "无妨，我来承受。",
}

skel:addEffect(fk.DetermineDamageCaused, {
  audio_index = {1, 2},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target and not target.chained and player:usedSkillTimes(skel.name) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      {
        skill_name = skel.name,
        prompt = "#lb__bishi::" .. target.id .. ":" .. data.damage .. ":" .. Fk:getDamageNatureName(data.damageType)
      })
  end,
  on_use = function(self, event, target, player, data)
    data:preventDamage()
  end,
})

skel:addEffect(fk.CardUsing, {
  audio_index = {3, 4},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and not target.chained and table.contains(data.tos, player) and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(target, { skill_name = skel.name, prompt = "#lb__bishi_chain" })
  end,
  on_use = function(self, event, target, player, data)
    target:setChainState(true)
    --[[
    local cards = target:getCardIds("he")
    if #cards > 0 then
      local room = player.room
      if #cards > 1 then
        cards = room:askToCards(target, {
          min_num = 1,
          max_num = 1,
          skill_name = skel.name,
          cancelable = false,
          include_equip = true,
          prompt = "#lb__bishi_recast",
        })
      end
      room:recastCard(cards, target, skel.name)
    end
    --]]
    if table.find(target:getCardIds("he"), function (id)
      return not target:prohibitDiscard(id)
    end) then
      player.room:askToDiscard(target, {
          min_num = 1,
          max_num = 1,
          skill_name = skel.name,
          cancelable = false,
          include_equip = true,
          prompt = "#lb__bishi_recast",
        })
    end
  end,
})

skel:addEffect("targetmod", {
  bypass_distances = function (self, player, skill, card, to)
    if player ~= to and to and to:hasSkill(skel.name) and card then
      return true
    end
  end,
})

return skel